//**************************************************
//	Digit Widgets Spiral Module
// 	Object Spiral Manipulation 
//	Made to be called from Hyperlinked Digit_Widgets Script
//
// Version 3.0 - 09/12/01 - Added Animation Script to Widgets
// Version 3.1 - 09/15/01 - Updated with Advanced and Standard Animation Scripts
//**************************************************
<zscriptinsert,"Digit_Widgets_Common_Std.txt">
[PD]
[FontSetColor,255,200,0]Spiral Object Functions[FontSetColor,160,160,160]
[PD]
//***************************
//Spiral Manipulation Variables
//***************************
[VarDef,spiralpts,63]
[VarDef,growth,.1]
[VarDef,sangle,0]
[VarDef,anglepts,1]
[VarDef,tmp3,0]
[VarDef,tmp4,0]
[VarDef,tmp5,0]
[VarDef,scurx,0]
[VarDef,scury,0]
[VarDef,scurz,0]
[VarDef,sshift,1]
[VarDef,Markselection,2]
[VarDef,ccntr,1]
[VarDef,cptr,1]
[VarDef,crecurse,0]
[VarDef,resultxs,0]
[VarDef,resultys,0]
[VarDef,resultzs,0]
[VarDef,resultxr,0]
[VarDef,resultyr,0]
[VarDef,resultzr,0]
[iSlider,"Iterations",0,.1,0,200,"Number of Spiral Points ",[VarSet,spiralpts,zscript:Iterations],0,[TextCalcWidth,Distance1453]]
[iSlider,"AnglePlier",1,.1,0,63,"Space between angle increments ",[VarSet,anglepts,zscript:AnglePlier],0,[TextCalcWidth,Distance1453]]
[iSlider,"XYScale",10,.01,.01,100,"Growth Factor ",[VarSet,growth,zscript:XYScale],0,[TextCalcWidth,XYAngle12345]]
[iSlider,"ZSAngle",0,.1,-1000,1000,"Z Angle ",[VarSet,zdangle,zscript:ZSAngle],0,[TextCalcWidth,ZAngle123456]]
[iSlider,"Shift",1,1,1,3,"Shift Axis ",[VarSet,sshift,zscript:Shift],0,[TextCalcWidth,ZAngle123456]]
[iSwitch,"Ztype",0,"Change Z calc"] 
[iSwitch,"SizeDepth",0,"Size to Zdepth"] 
[iSwitch,"SizeRotateMarkers",0,"Size and rotate to Markers"] 
[iSlider,"EndMarker",2,1,1,10,"Select End Marker for size and rotation ",[VarSet,Markselection,zscript:EndMarker],0,[TextCalcWidth,ZAngle123456]]
[iSwitch,"SpiralFromMark",0,"Center Object at current Mark"] 
[iButton," Do Spiral ","Draw Object Spiral",

	[if,[iGet,zscript:SpiralFromMark],
		[TransformSet,MarkX(MarkIndex),MarkY(MarkIndex),MarkZ(MarkIndex),MarkXS(MarkIndex),MarkYS(MarkIndex),MarkZS(MarkIndex)]
	]
	// got to get how much time the number of iterations are
	[if,[IGet,zscript:SizeRotateMarkers],
		[VarSet,ccntr,1.0/spiralpts]	
		[VarSet,cptr,1]	
	]

	[TransformGet,scurx,scury,scurz]

	[VarSet,tmp5,0]
	[VarSet,sangle,0]
	[Loop,spiralpts,
		[if,sshift=1,
			[VarSet,XD1,sangle*COS(tmp5)]
			[VarSet,YD1,sangle*SIN(tmp5)]
			[if,[iGet,zscript:Ztype],
				[VarSet,ZD1,zdangle*sangle]
			,//else
				// use rotate around z axis for z
				[VarSet,tmp3,SIN(zdangle)*XD1]
				[VarAdd,tmp4,COS(zdangle)*YD1]
				[VarSet,ZD1,tmp3+tmp4]
			]
		]
		[if,sshift=2,
			[VarSet,ZD1,sangle*COS(tmp5)]
			[VarSet,XD1,sangle*SIN(tmp5)]
			[if,[iGet,zscript:Ztype],
				[VarSet,YD1,zdangle*sangle]
			,//else
				// use rotate around z axis for z
				[VarSet,tmp3,SIN(zdangle)*ZD1]
				[VarAdd,tmp4,COS(zdangle)*XD1]
				[VarSet,YD1,tmp3+tmp4]
			]
		]
		[if,sshift=3,
			[VarSet,YD1,sangle*COS(tmp5)]
			[VarSet,ZD1,sangle*SIN(tmp5)]
			[if,[iGet,zscript:Ztype],
				[VarSet,XD1,zdangle*sangle]
			,//else
				// use rotate around z axis for z
				[VarSet,tmp3,SIN(zdangle)*YD1]
				[VarAdd,tmp4,COS(zdangle)*ZD1]
				[VarSet,XD1,tmp3+tmp4]
			]
		]
		[VarSet,tmp5,tmp5-growth]
		[VarSet,XD1,XD1+scurx]
		[VarSet,YD1,YD1+scury]
		[VarSet,ZD1,ZD1+scurz]
		[TransformSet,XD1,YD1,ZD1]
		[if,[iGet,zscript:SizeDepth],
			[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
			[RoutineCall,DepthCalc]
		]//Endif
		[if,[IGet,zscript:SizeRotateMarkers],
			[VarSet,crecurse,ccntr*cptr]
			[VarSet,resultxs,[Interpolate,crecurse,MarkXS(MarkIndex),MarkXS(Markselection)]]
			[VarSet,resultys,[Interpolate,crecurse,MarkYS(MarkIndex),MarkYS(Markselection)]]
			[VarSet,resultzs,[Interpolate,crecurse,MarkZS(MarkIndex),MarkZS(Markselection)]]
			[VarSet,resultxr,[Interpolate,crecurse,MarkXR(MarkIndex),MarkXR(Markselection)]]
			[VarSet,resultyr,[Interpolate,crecurse,MarkYR(MarkIndex),MarkYR(Markselection)]]
			[VarSet,resultzr,[Interpolate,crecurse,MarkZR(MarkIndex),MarkZR(Markselection)]]
			[TransformSet,,,,resultxs,resultys,resultzs,resultxr,resultyr,resultzr]
			[VarInc,cptr]
		]
		

		//snapshot this bugger
		[IPress,Transform:Snapshot]
		[VarSet,sangle,sangle+anglepts]
	]
]

[PD]
[pd][penMove,0,8]
<zscriptinsert,"Widgets_Index_Include_Std.txt">
[pd][penMove,0,8]
\C00e0e0About This ZScript:
\Cc0c0c0This script will allow you to create a spiral around a defined Postion Marker or in space by providing (an \Cffa000Number of Spiral Points\Cc0c0c0 , \Cffa000A AnglePlier\Cc0c0c0), \Cffa000A XYScale\Cc0c0c0) and a \Cffa000A ZAngle\Cc0c0c0). The combination of these variables determine the magnitude and size of the spiral and experimentation is encouraged. To start off with a value of 60 for Spiral Points, 1 AnglePlier, 20 XYScale and 90 for Zangle will get you started with the \Cffa000ZType\Cc0c0c0 Switch off. Turning \Cffa000ZType\Cc0c0c0 switch off converts the sprial to a different type. NOTE Make sure that your Zangle is small, say 1 to 5 when you are using the \Cffa000ZType\Cc0c0c0 spiral. 
By using the \Cffa000Shift\Cc0c0c0 slider 1-3 you are actually changing the Axis Calculation from XYZ to YZX and ZXY. Experiment with this, only really makes a great difference when you are using the \Cffa000ZType\Cc0c0c0 Spiral

Experiment also with Positive and Negative values for \Cffa000A ZAngle\Cc0c0c0) as it will determine in which direction the spiral will move. i.e. Up, Down, Left or Right.

The \Cffa000Important\Cc0c0c0 to use this script you must be holding the desired object in either Move, Scale or Rotation mode, in other words the Gyro must be visible for the script to manipulate the desired object.
[PD]
[iButton,"Example ","Interpolation Widget Example",
	[if,[Ireset],
	[IcolorSet,239,234,30]
	[note,"I will select a Sphere, any object can be used however",zscript:example,2]
	[ISet,Tool:ItemInfo,8]
	[note,"Drag it onto Canvas",zscript:example,1]
	[CanvasClick,DocMidX,DocMidY,DocMidX+10,DocMidY+10]
	[IPress,Transform:Move]
	[note,"Notice that I am holding the object now in a Transform Move, Scale, or Rotation mode and that the Gyro is visible. Next I will use the Position Marker Widget feature and save its Position as Marker 1",zscript:example,0]
	[ISet,zscript:SelectMark,1]
	[Ipress,zscript:Save]
	[IPress,Transform:Snapshot]
	[Note,"The Spiral Origin can be tied to a mark by pressing the SpiralFromMark switch or begin wherever you position the object on the canvas. For this example we will select SpiralFromMark",zscript:example,0]
	[if,[IGet,zscript:SpiralFromMark],
	,
		[IPress,zscript:SpiralFromMark]
	]
	[note,"Different Spirals can be obtained by using different settings. I will set Iterations to 60, AnglePlier to 1, XYScale to 20 and ZSAngle to 90. ZType switch OFF",zscript:example,0]
	[Iset,zscript:iterations,60]
	[Iset,zscript:AnglePlier,1]
	[Iset,zscript:XYScale,20]
	[Iset,zscript:ZSAngle,90]
	[if,[IGet,zscript:ZType],
		[IToggle,zscript:Ztype]
	]
	[note,"Setting SizeDepth will size the objects according to the current ZDepth Reference (Default 500) or you can provide another Position Marker reference and select SizeRotateMarkers and have the objects rotate and size itself as the spiral progresses. ",zscript:example,0]
	[IPress,zscript:DoSpiral]
	[Note,"This is one type of spiral, select ZType to change the algorithum. IMPORTANT For this type I will set the ZSAngle to a small value say -3. Use a negative number to make it spiral toward you. ",zscript:example,0]
	[if,[IGet,zscript:ZType],
	,
		[IToggle,zscript:Ztype]
	]
	[Iset,zscript:ZSAngle,-3]
	[note,"Turning Off SpiralFromMark",zscript:example,1]
	[if,[IGet,zscript:SpiralFromMark],
		[IToggle,zscript:SpiralFromMark]
	]
	[IPress,layer:modifiers:clear]
	[Transformset,DocMidX,DocMidY,0]
	[IPress,zscript:DoSpiral]
	[note,"Here it is! By using the Shift slider you can rotate the spiral Axis from XYZ to YZX or ZXY to produce upwards/Downwards or Left/Right sprials dependant on whether or not ZSAngle is Positive or Negative. Here is a downward sprial",zscript:example,0]
	[note,"Changing Shift to 2",zscript:example,1]
	[ISet,zscript:Shift,2]
	[Iset,zscript:ZSAngle,3]
	[IPress,zscript:DoSpiral]
	[note,"And here is a Right going Spiral",zscript:example,0]
	[note,"Changing Shift to 3",zscript:example,1]
	[ISet,zscript:Shift,3]
	[IPress,zscript:DoSpiral]
	[Note,"Do some experiments to see how the different inputs control the widget",zscript:example,0]
,//else
	[Note,"Aborting! Maybe another day eh?",,3]
]
]

[PD]
[PD]
[fontSetSizeSmall]\C00e0e0Standard Digit Widget Spiral Revision 1.0, created by Digits\Cc0c0c0
